package kr.hkit.androidcomplete01.ch07;

import kr.hkit.androidcomplete01.ch07.DrawPath.MyView;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RadialGradient;
import android.graphics.Shader.TileMode;
import android.os.Bundle;
import android.view.View;

public class ShaderGradient extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(new MyView(this));
	}

	class MyView extends View {
		
		private Paint paint;
		private int[] colors;
		private float[] pos;
		
		public MyView(Context context) {
			super(context);
			paint = new Paint(Paint.ANTI_ALIAS_FLAG);
			colors = new int[] {Color.RED, Color.GREEN, Color.BLUE, 
					Color.YELLOW, Color.WHITE};
			pos = new float[] {0.0f, 0.1f, 0.6f, 0.9f, 1.0f};
		}
		
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);

			//우하향
			paint.setShader(new LinearGradient(110, 0, 210, 100, Color.BLUE, 
					Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(110, 0, 210, 100, paint);
			
			//가장자리 반복
			paint.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE, 
					Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(0, 110, 320, 150, paint);
			
			//무늬 반복
			paint.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE, 
					Color.WHITE, TileMode.REPEAT));
			canvas.drawRect(0, 160, 320, 200, paint);
			
			//여러 가지 색상 균등 배치
			paint.setShader(new LinearGradient(0, 0, 320, 0, colors, 
					null, TileMode.CLAMP));
			canvas.drawRect(0, 260, 320, 300, paint);
			
			//여러 가지 색상 임의 배치
			paint.setShader(new LinearGradient(0, 0, 320, 0, colors, 
					pos, TileMode.CLAMP));
			canvas.drawRect(0, 310, 320, 350, paint);
			
			//원형 
			//여러가지 색 균등
			paint.setShader(new RadialGradient(80, 450, 70, colors, null, TileMode.CLAMP));
			canvas.drawCircle(80, 450, 70, paint);
			
			//여러가지 색 차등
			paint.setShader(new RadialGradient(250, 450, 70, colors, pos, TileMode.CLAMP));
			canvas.drawCircle(250, 450, 70, paint);
			
			
		}
	}
}
